from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-21 14:17:03.519664
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 21, Oct, 2022
Time: 14:17:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7762
Nobs: 816.000 HQIC: -51.0960
Log likelihood: 10597.7 FPE: 5.28235e-23
AIC: -51.2951 Det(Omega_mle): 4.73389e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.292787 0.052216 5.607 0.000
L1.Burgenland 0.108841 0.035248 3.088 0.002
L1.Kärnten -0.106489 0.018777 -5.671 0.000
L1.Niederösterreich 0.210838 0.073754 2.859 0.004
L1.Oberösterreich 0.101396 0.070727 1.434 0.152
L1.Salzburg 0.250155 0.037522 6.667 0.000
L1.Steiermark 0.037746 0.049164 0.768 0.443
L1.Tirol 0.106506 0.039868 2.671 0.008
L1.Vorarlberg -0.058216 0.034285 -1.698 0.090
L1.Wien 0.060801 0.063066 0.964 0.335
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062277 0.108012 0.577 0.564
L1.Burgenland -0.032946 0.072913 -0.452 0.651
L1.Kärnten 0.047769 0.038841 1.230 0.219
L1.Niederösterreich -0.172316 0.152565 -1.129 0.259
L1.Oberösterreich 0.385534 0.146302 2.635 0.008
L1.Salzburg 0.286330 0.077616 3.689 0.000
L1.Steiermark 0.105214 0.101699 1.035 0.301
L1.Tirol 0.314018 0.082469 3.808 0.000
L1.Vorarlberg 0.025525 0.070921 0.360 0.719
L1.Wien -0.014871 0.130455 -0.114 0.909
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188698 0.026795 7.042 0.000
L1.Burgenland 0.090475 0.018088 5.002 0.000
L1.Kärnten -0.008454 0.009636 -0.877 0.380
L1.Niederösterreich 0.264585 0.037848 6.991 0.000
L1.Oberösterreich 0.126066 0.036294 3.473 0.001
L1.Salzburg 0.048468 0.019255 2.517 0.012
L1.Steiermark 0.017178 0.025229 0.681 0.496
L1.Tirol 0.094794 0.020459 4.633 0.000
L1.Vorarlberg 0.059409 0.017594 3.377 0.001
L1.Wien 0.119754 0.032363 3.700 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108312 0.027464 3.944 0.000
L1.Burgenland 0.044734 0.018539 2.413 0.016
L1.Kärnten -0.016157 0.009876 -1.636 0.102
L1.Niederösterreich 0.193044 0.038792 4.976 0.000
L1.Oberösterreich 0.293514 0.037199 7.890 0.000
L1.Salzburg 0.115900 0.019735 5.873 0.000
L1.Steiermark 0.099743 0.025858 3.857 0.000
L1.Tirol 0.116901 0.020969 5.575 0.000
L1.Vorarlberg 0.070787 0.018033 3.925 0.000
L1.Wien -0.027263 0.033170 -0.822 0.411
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122446 0.049916 2.453 0.014
L1.Burgenland -0.050686 0.033696 -1.504 0.133
L1.Kärnten -0.040491 0.017950 -2.256 0.024
L1.Niederösterreich 0.170152 0.070506 2.413 0.016
L1.Oberösterreich 0.137862 0.067612 2.039 0.041
L1.Salzburg 0.285511 0.035870 7.960 0.000
L1.Steiermark 0.033343 0.046999 0.709 0.478
L1.Tirol 0.166137 0.038112 4.359 0.000
L1.Vorarlberg 0.104871 0.032775 3.200 0.001
L1.Wien 0.072726 0.060288 1.206 0.228
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059019 0.039497 1.494 0.135
L1.Burgenland 0.039358 0.026662 1.476 0.140
L1.Kärnten 0.050738 0.014203 3.572 0.000
L1.Niederösterreich 0.225619 0.055788 4.044 0.000
L1.Oberösterreich 0.282181 0.053498 5.275 0.000
L1.Salzburg 0.051628 0.028382 1.819 0.069
L1.Steiermark -0.007947 0.037188 -0.214 0.831
L1.Tirol 0.149967 0.030156 4.973 0.000
L1.Vorarlberg 0.071218 0.025933 2.746 0.006
L1.Wien 0.079116 0.047703 1.659 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174357 0.047213 3.693 0.000
L1.Burgenland -0.005537 0.031871 -0.174 0.862
L1.Kärnten -0.061173 0.016978 -3.603 0.000
L1.Niederösterreich -0.083523 0.066687 -1.252 0.210
L1.Oberösterreich 0.192875 0.063950 3.016 0.003
L1.Salzburg 0.057531 0.033927 1.696 0.090
L1.Steiermark 0.229598 0.044453 5.165 0.000
L1.Tirol 0.494976 0.036048 13.731 0.000
L1.Vorarlberg 0.050020 0.031000 1.614 0.107
L1.Wien -0.047102 0.057023 -0.826 0.409
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160439 0.054168 2.962 0.003
L1.Burgenland -0.011279 0.036566 -0.308 0.758
L1.Kärnten 0.065923 0.019479 3.384 0.001
L1.Niederösterreich 0.200627 0.076511 2.622 0.009
L1.Oberösterreich -0.061168 0.073370 -0.834 0.404
L1.Salzburg 0.217184 0.038924 5.580 0.000
L1.Steiermark 0.113496 0.051002 2.225 0.026
L1.Tirol 0.077742 0.041358 1.880 0.060
L1.Vorarlberg 0.124688 0.035567 3.506 0.000
L1.Wien 0.114291 0.065423 1.747 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351542 0.031583 11.131 0.000
L1.Burgenland 0.006036 0.021320 0.283 0.777
L1.Kärnten -0.023646 0.011357 -2.082 0.037
L1.Niederösterreich 0.224090 0.044611 5.023 0.000
L1.Oberösterreich 0.174565 0.042779 4.081 0.000
L1.Salzburg 0.048342 0.022695 2.130 0.033
L1.Steiermark -0.016511 0.029737 -0.555 0.579
L1.Tirol 0.109643 0.024114 4.547 0.000
L1.Vorarlberg 0.073873 0.020738 3.562 0.000
L1.Wien 0.053181 0.038146 1.394 0.163
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041528 0.152425 0.189905 0.158759 0.124717 0.114865 0.065745 0.226710
Kärnten 0.041528 1.000000 -0.002520 0.129913 0.042315 0.096218 0.429637 -0.052992 0.101163
Niederösterreich 0.152425 -0.002520 1.000000 0.337562 0.155410 0.300869 0.111612 0.184209 0.328592
Oberösterreich 0.189905 0.129913 0.337562 1.000000 0.233089 0.333147 0.173215 0.172795 0.263565
Salzburg 0.158759 0.042315 0.155410 0.233089 1.000000 0.147246 0.129248 0.149417 0.135174
Steiermark 0.124717 0.096218 0.300869 0.333147 0.147246 1.000000 0.154076 0.141126 0.079611
Tirol 0.114865 0.429637 0.111612 0.173215 0.129248 0.154076 1.000000 0.115474 0.155460
Vorarlberg 0.065745 -0.052992 0.184209 0.172795 0.149417 0.141126 0.115474 1.000000 0.007746
Wien 0.226710 0.101163 0.328592 0.263565 0.135174 0.079611 0.155460 0.007746 1.000000